//时间转时间戳
function formatTimestamp(timestamp, format1 = 'yyyy/MM/dd hh:mm:ss') {
    let format = format1;
    let time = new Date(timestamp);
    if (isNaN(time.getTime()) || time.getTime() < new Date('2000/1/1')) return '';
    let date = {
        'M+': time.getMonth() + 1,
        'd+': time.getDate(),
        'h+': time.getHours(),
        'm+': time.getMinutes(),
        's+': time.getSeconds(),
        'q+': Math.floor((time.getMonth() + 3) / 3),
        'S+': time.getMilliseconds()
    };
    if (/(y+)/i.test(format)) {
        format = format.replace(RegExp.$1, String(time.getFullYear()).substr(4 - RegExp.$1.length));
    }
    for (let k in date) {
        if (new RegExp('(' + k + ')').test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? date[k] : ('00' + date[k]).substr(String(date[k]).length));
        }
    }
    return format;
}

const common = {
    formatTimestamp
}

export default common;